package test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import hyl.core.MyDate;
import hyl.core.MyFun;
import hyl.core.run.IDo;
import hyl.core.run.MyTimer;

public class demodate {
	private static String firstDay;
	private static String lastDay;

	public static void main(String[] args) {
		/*
		 * Schedule.monStart(new IDo<Calendar>() {
		 * 
		 * @Override public void run(Calendar obj) throws Exception { // TODO
		 * Auto-generated method stub System.out.println(MyFun.date2Str(obj.getTime(),
		 * "yyyy-MM-dd HH:mm:ss")); } }, MyFun.str2Datetime("2019-2-3 10:50:00"), 0);
		 */
	//	;
		//System.out.println(MyFun.str2int(MyDate.getFirstOfLastMon("yyyyMM")));
		/*
		 * Date date1=MyFun.str2Date("1970-01-16 12:00:00"); Date
		 * date2=MyFun.str2Date("2019-3-6 00:00:00"); Date
		 * date3=MyFun.str2Date("2019-3-4 23:59:59"); Date
		 * date4=MyFun.str2Date("2019-3-6 00:00:00");
		 */
		
		
	//	System.out.println(MyFun.date2Str(MyDate.addDays(MyFun.str2Date("2019-3-6"),-17960)));
		//fun1(date3,date4);
		//fun1_1(date1,date2);
		
		System.out.println(MyFun.date2Str(get第一天(0)));
	}
	static Date 基准日=MyFun.str2Date("2019-07-01");
	public static Date get第一天(int 第几周) {
		Date d2=基准日;
		if(第几周>0)
			d2=MyDate.addDays(d2,  第几周*7);
		return d2;
	}
	public static void fun1(Date date1,Date date2) {	
		System.out.println(MyDate.getDaysOfT2_T1(date1,date2));
	}
	public static void fun1_1(Date date1,Date date2) {

		System.out.println(MyDate.getMSecondsOfT2_T1(date1,date2));
	}
	public static void fun2(Date date1,Date date2) {
		String sdate=MyFun.date2Str(date2);		
		System.out.println(sdate);
	
		
		MyTimer.getInstance("日结算").monStart(new IDo<Calendar>() {
			@Override
			public void run(Calendar obj) throws Exception {
				System.out.println("疯狂方块"+MyDate.getCurrTime());
			}
		},date2,1);
	}
	public static void testday() {
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");

		// 获取前月的第一天
		Calendar cal_1 = Calendar.getInstance();// 获取当前日期

		System.out.println("-----0------now:" + format.format(cal_1.getTime()));
		cal_1.add(Calendar.MONTH, -1);
		cal_1.set(Calendar.DAY_OF_MONTH, 1);// 设置为1号,当前日期既为本月第一天
		firstDay = format.format(cal_1.getTime());
		System.out.println("-----1------firstDay:" + firstDay);
		// 获取前月的最后一天
		Calendar cale = Calendar.getInstance();
		cale.set(Calendar.DAY_OF_MONTH, 1);// 设置为1号,当前日期既为本月第一天
		lastDay = format.format(cale.getTime());
		System.out.println("-----2------lastDay:" + lastDay);

		// 获取当前月第一天：
		Calendar c = Calendar.getInstance();
		c.add(Calendar.MONTH, 0);
		c.set(Calendar.DAY_OF_MONTH, 1);// 设置为1号,当前日期既为本月第一天
		String first = format.format(c.getTime());
		System.out.println("===============first:" + first);

		// 获取当前月最后一天
		Calendar ca = Calendar.getInstance();

		System.out.println("===============last2:" + ca.getActualMaximum(Calendar.DAY_OF_MONTH));

		ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH));
		String last = format.format(ca.getTime());
		System.out.println("===============last:" + last);
		// 获取当前月最后一天
		Calendar c2 = Calendar.getInstance();

		c2.add(Calendar.MONTH, 1);
		c2.set(Calendar.DAY_OF_MONTH, 0);

		System.out.println("===============last3:" + format.format(c2.getTime()));
	}

	/**
	 * 字符串的日期格式的计算
	 */
	public static int daysBetween(String smdate, String bdate) throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Calendar cal = Calendar.getInstance();
		cal.setTime(sdf.parse(smdate));
		long time1 = cal.getTimeInMillis();
		cal.setTime(sdf.parse(bdate));
		long time2 = cal.getTimeInMillis();
		long between_days = (time2 - time1) / (1000 * 3600 * 24);
		return Integer.parseInt(String.valueOf(between_days));
	}
}
